package com.travelsupport.ui;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.travelsupport.controller.DbController;
import com.travelsupport.controller.NetworkController;
import com.travelsupport.myobject.AdvertiseObj;
import com.travelsupport.myobject.CurrencyObj;
	
	
	public class CurrencyActivity extends Activity {	
		DbController dbController = null;
		AdvertiseObj adObj = null;
		private Context context = this;
		private NetworkController networkController = null;
		
		@Override
		public void onCreate(Bundle savedInstanceState) {
			// TODO Auto-generated method stub
			super.onCreate(savedInstanceState);
			setContentView(R.layout.activity_currency);
		
	    	if(networkController == null)
	    	{
	    		networkController = new NetworkController(context);
	    	}
	    	
	    	if(networkController.checkNetworkConnected())
			{
				showListCurrency();
				
				//footer
				TextView txtAdvertise = (TextView) findViewById(R.id.advertise);
				
				dbController = new DbController(this);
				dbController.openDb();
				adObj = dbController.selectAdvertise();
				dbController.closeDb();
				txtAdvertise.setText(adObj.adName.toString());
				
				txtAdvertise.setOnClickListener(new OnClickListener() {
					
					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						Log.d("Phuong at currency222222","url=" + adObj.adURL.toString());
						Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(adObj.adURL.toString())); 
				        startActivity(intent);
					}
				});
				
			}else 
			{
				Toast.makeText(this,"Network is not available, please try again!",Toast.LENGTH_SHORT).show();
			}
			

		}
		
		public void Setting(View v)
		{
			startActivity(new Intent(CurrencyActivity.this,SettingActivity.class));
		}
		
		
		private void showListCurrency()
		{
			ListView lvCustomList = (ListView) findViewById(R.id.list_currency);
			dbController = new DbController(this);
			dbController.openDb();
			List<CurrencyObj> currencyList = dbController.selectAllCurrency();
			dbController.closeDb();
			
			CurrencyAdapter currencyListAdapter = new CurrencyAdapter(CurrencyActivity.this, currencyList);
			lvCustomList.setAdapter(currencyListAdapter);
			
			
		}
	}

